<?php

class User_ModifyController extends Zend_Controller_Action{
	
	private $userId;
	
	public function preDispatch(){
		if(Zend_Auth::getInstance()->getIdentity()){
			$this->userId = Zend_Auth::getInstance()->getIdentity()->id;
		}
	}
	
	public function addressAction(){
		
		$data = Doctrine_Model_UserAddresses::getAddress($this->userId);
		
		$form = new Custom_Form_Address(array(
			'action'	=>	'/user/modify/address',
			'method'	=>	'post'
		));
		
		
		$request = $this->getRequest();
		if($request->isPost()){
			if($form->isValid($request->getPost())){
				$data = $form->getValues();
				$result = Doctrine_Model_UserAddresses::setAddress($this->userId, $data);
				
				if($result){
//					Modify successful
				}else{
//					Modify unsuccesful
				}
			}
		}
		
		$form->populate($data);
		$this->view->form = $form;
	}
	public function contactAction(){
		
		$data = Doctrine_Model_UserContacts::getContact($this->userId);
		
		$form = new Custom_Form_Contact(array(
			'action'	=>	'/user/modify/contact',
			'method'	=>	'post'
		));
		
		$request = $this->getRequest();
		if($request->isPost()){
			if($form->isValid($request->getPost())){
				$data = $form->getValues();
				$result = Doctrine_Model_UserAddresses::setAddress($this->userId, $data);
				
				if($result){
//					Modify successful
				}else{
//					Modify unsuccesful
				}
			}
		}
		
		$form->populate($data);
		$this->view->form = $form;
	}
	public function paymentAction(){
		
		$data = Doctrine_Model_UserPayments::getPayment($this->userId);
		
		$form = new Custom_Form_Payment(array(
			'action'	=>	'/user/modify/payment',
			'method'	=>	'post'
		));
		
		$request = $this->getRequest();
		if($request->isPost()){
			if($form->isValid($request->getPost())){
				$data = $form->getValues();
				$result = Doctrine_Model_UserAddresses::setAddress($this->userId, $data);
				
				if($result){
//					Modify successful
				}else{
//					Modify unsuccesful
				}
			}
		}
		
		$form->populate($data);
		$this->view->form = $form;
	}
}